var server = require('../../utils/server');
var global = getApp();
var utils = require('../../utils/util.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    url:'',
    bottomtext: '更多',
    page: 1,
    loadtxt: '正在加载',
    loading: false
    
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function () {
    var that = this;
    server.getJSON("/video_data", function (res) {
      var data = res.data;
      for (var i = 0; i < data.length; i++) {
        data[i]['images'] = global.imgurl(data[i]['images']);
      }
      console.log('diyiyeshuju', data);
      that.setData({
        data: data
      });
    });
  },
  /**
   * 用户点击右上角分享
   */

  loadMore(e) {
    console.log(e);
    var page = e.currentTarget.dataset.page;
    var pages = page + 1;
    var that = this
    that.setData({
      loading: true,
      page: pages
    })
    var that = this;
    var old_data = that.data.data;
    wx.request({
      url: 'http://localhost/index.php/Port/video_more/page/' + pages,
      headers: {
        'Content-Type': 'application/json'
      },
      success(res) {
        var data = res.data;
        console.log(res);
        for (var i = 0; i < data.length; i++) {
          data[i]['images'] = global.imgurl(data[i]['images']);
          old_data.push(data[i]);
        }

        that.setData({
          loading: false,
          data: old_data
        })
        if (data.msg == '数据为空') {
          that.setData({
            bottomtext: '已加载全部'
          })
        }
      }
    })
  },
  powerDrawer: function (e) {
    var url = e.currentTarget.dataset.url;
    console.log(url);
    var currentStatu = e.currentTarget.dataset.statu;
    this.util(currentStatu)
    var that=this;
    that.setData({
      url: url
    })
    },  
  util: function (currentStatu) {
    console.log(currentStatu);
    /* 动画部分 */
    // 第1步：创建动画实例   
    var animation = wx.createAnimation({
      duration: 200,  //动画时长  
      timingFunction: "linear", //线性  
      delay: 0  //0则不延迟  
    });

    // 第2步：这个动画实例赋给当前的动画实例  
    this.animation = animation;

    // 第3步：执行第一组动画  
    animation.opacity(0).rotateX(-100).step();

    // 第4步：导出动画对象赋给数据对象储存  
    this.setData({
      animationData: animation.export()
    })

    // 第5步：设置定时器到指定时候后，执行第二组动画  
    setTimeout(function () {
      // 执行第二组动画  
      animation.opacity(1).rotateX(0).step();
      // 给数据对象储存的第一组动画，更替为执行完第二组动画的动画对象  
      this.setData({
        animationData: animation
      })

      //关闭  
      if (currentStatu == "close") {
        this.setData(
          {
            showModalStatus: false
          }
        );
      }
    }.bind(this), 200)

    // 显示  
    if (currentStatu == "open") {
      this.setData(
        {
          showModalStatus: true
        }
      );
    }
  }  
  

})